package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"youngwind-first/rpcdemo/internal/svc"
	"youngwind-first/rpcdemo/model/gorm_model"
	"youngwind-first/rpcdemo/rpcdemo"
)

type AddUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserLogic {
	return &AddUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddUserLogic) AddUser(in *rpcdemo.UserAdd) (*rpcdemo.Success, error) {
	u := gorm_model.User{
		Name: in.Name,
		Age:  in.Age,
	}
	err := l.svcCtx.DbEngin.Create(&u).Error
	if err != nil {
		return nil, err
	}

	return &rpcdemo.Success{}, nil
}
